Dart Project - Rock Paper Scissors

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
assalamualaikum boys in this video i will be showing you how to make rock paper and scissor with dart for this let us fire up our vs code and i will drag this folder here let us make a new file rps dot dart now we will start with our main method the void main and firstly i want to make a while condition because the game will run infinitely so while true and within this body let us start now firstly when the when a user fires up this program i would like to show an output so for that i will use standard out dot right welcome to [Music] rock paper or scissors slash quit and i would like to give a shortcut to this too so r b or s slash q and then all right this is my print outline and i want to capture what the user inputs in a final input variable input standard in dot read line sync all right now here i will start writing the player move section selecting layer move now before i start let us go up here and let's make a enum rock paper scissors oh i'm sorry in the move rock paper and caesar all right now within this body if uh input equals to r it should be player move equals to move dot rock i should make a variable here bar layer move now i i made this variable and i didn't initialize it because if the input is r i want to put the value of inum move rock within this variable so if input is r player move equals to move dot rock all right else if input equals to p layer move equals to move dot paper else if input equals to s player move equals to move dot scissors else if input is you i would like to break this uh program so if the user hits q the loop will stop here and the program will quit all right in all other cases else print in valid input all right i like that now the thing is uh if the player hits r it's a player move dot rock if p move paper if s moves easier if you it is going to break and in all other case it is going to print invalid input because there is nothing that you can put other than rp s and q all right that being said let us select the ai move for that i will make a new section here select a i move uh final let us make a random number which is going to be random and we need to import this random first from dart math io dot next end and with a maximum of three because two is a as up as i we can go and final a i move equals to move dot values and within the list we're going to put random number all right now what did i do here what i did here is uh we made a random number generator here and this random number generator is going to have a maximum value of two so whatever you whatever you put here it is going to be one less than that since we have here three values so the first one starts with zero one and two that's how uh lists work so here we are going to put three because it's going to be zero one and two and the ai move is going to be a move a move and a random number generator which is going to show the index index if zero it's rock if one it's paper if two it's caesar so move dot if zero rock if one it's paper if two it's caesar i hope that was clear and then we are going to showing player move and ai move so we are going to show what the player played and what the ai plate for this print you played dollar sign layer move all right and print i played dollar sign ai move all right now let us implement the game logic logic [Music] all right what should we do we should start with the if statement if player move equals tools to move dot let's start with rock rock and a i move equals to move dot uh rock it should be caesar right yeah caesar or or layer move equals to move dot paper and a i move equals to move dot um sorry give me a second move the truck right yeah move that rock or player move equals to move dot caesar and a i move equals to move dot um paper all right in this case i will hit the ctrl s all right to reformat so here is the logic in this case print you win else if uh player move equals to a i move we are going to print print it's a draw draw else in all other cases since there can be just three kind of case this here is the case where the player wins this here is the case where the where is the draw and in all other case it is going to be the ai winning so we are going to print you lose boo all right i hope that's it yeah that's it let us ctrl s and ctrl what is this something whatever let us clear it in the terminal we are going to press start and tap enter all right welcome to rock paper or caesar slash quit so if i put r enter you played move dot rock airplayed move dot paper so i lost what the heck all right r again you win r again you lost r again you lost so all right all three conditions are working so let us go for p p p s s s and q all right that's it i hope this was clear and it's a very straightforward program if you even if you are new to programming you can just read it and understand what is happening what's going through and how it's working because it's very easily and well laid out i hope this was clear and i will be posting it in my github repository and i'll be linking it down in the description below until next time allah hafiz
Info
Channel: Fluttercraft
Views: 95
Rating: undefined out of 5
Keywords:
Id: m9hs88qVfbg
Channel Id: undefined
Length: 10min 28sec (628 seconds)
Published: Sat Dec 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.