Posts

Showing posts with the label 2d

Index out of range exception in 2D Array (C#)

Index out of range exception in 2D Array (C#) char[,] map = new char[10, 20]; for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; i < map.GetLength(1); j++) map[i, j] = '.'; } I just simply want to make all the elements of map[i,j] to be a point , but always when I try to run it the compiler says: Index out of range exception. Maybe it's a stupid question but I had to ask it. 2 Answers 2 See the i in your j-loop i for (int j = 0; j < map.GetLength(1); j++) Thank you!And that proves that it was a silly question, thank you again! – Jurás Bence Aug 26 '13 at 10:02 You use i instead of j look at this: i j char[,] map = new char[10, 20]; for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j <...

How can I create a 2d array with labels, without numpy or pandas, from two lists for Python?

How can I create a 2d array with labels, without numpy or pandas, from two lists for Python? Let's say I have scores for five Rock, Paper, Scissors games that look like this: player_score = [1,0,1,1,0] cpu_score = [0,1,0,0,1] I want to make a 2d array (without numpy or pandas) that keeps a record of the games played(Like a scoreboard). So the final output would look 'something' resembled to this: G1 G2 G3 G4 G5 Player 1 0 1 1 0 CPU 0 1 0 0 1 Any suggestions? Does my answer work? – Abhishek Jul 2 at 1:09 No (I updated my question, forgot about pandas) I got: Traceback (most recent call last): File "************************", line 11, in <module> import pandas as pd ModuleNotFoundError: No module named 'pandas' – Lotus Alice ...

how can I detect collision in a 2D tile game map

how can I detect collision in a 2D tile game map I made this basic game where I drew a map and a player, the player can move anywhere but how can I make so that it wont move when its on the tile[1] in the map? also when I try to check if the player.x is greater than 50 it could go left it works but than if I click 2 keys at once it goes through const context = document.querySelector("canvas").getContext("2d"); var rgb = 'rgb(' + Math.random()*256 + ',' + Math.random()*256 + ',' + Math.random()*256 + ','+Math.random() + ')'; document.onload = Loop(); var width = 1500; var height = 800; function Loop(){ var width = 1500; var height = 800; context.canvas.height = height; context.canvas.width = width; this.interval = setInterval(Update, 1000/100); } const Player = function(x, y, w, h, color) { this.x = x; this.y = y; this.w = w; this.h = h; this.speedY = 0; this.speedX = 0; this.Draw = function(){ context.f...